package com.atguigui.leetcode;

/**
 * 883.三维形体投影面积
 * <p>
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/4/26 9:03
 */
public class P883ProjectionAreaOf3dShapes {
    public static void main(String[] args) {
        Solution solution = new P883ProjectionAreaOf3dShapes().new Solution();
        // TO TEST
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int projectionArea(int[][] grid) {

            int n = grid.length;

            int xy = 0;
            int yz = 0;
            int zx = 0;

            for (int i = 0; i < n; i++) {
                int yzHeight = 0, zxHeight = 0;

                for (int j = 0; j < n; j++) {
                    //xy 平面的投影面积等于网格上非零数值的数目；
                    xy += grid[i][j] > 0 ? 1 : 0;
                    //每行的最大值
                    yzHeight = Math.max(yzHeight, grid[i][j]);
                    // 每列的最大值
                    zxHeight = Math.max(zxHeight, grid[j][i]);
                }
                //yz 平面的投影面积等于网格上每一行最大数值之和；
                yz += yzHeight;
                //zx平面的投影面积等于网格上每一列最大数值之和。
                zx += zxHeight;
            }
            return xy + yz + zx;
        }
    }
}
